// pages/book-success/book-success.js
import { storeApi } from '../../api/index';
// 获取app
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: null,
    reservationInfo: {},
    store_info:{},
    reservatioTime: "",
    reservatioText: "",
  },

  async getInfo() {
    try {
      const { id } = this.data
      const res = await storeApi.getReservationOrderDetail({ id })
      this.setData({
        reservationInfo: res,
        store_info: res.store_info,
        reservatioTime: res.start_time_block_info.start_at,
        reservatioText: `${res.hairdye_type_info.name}、${res.hairdye_color_info.name}、${res.hair_region_info.name}`,
      })
    } catch (e) { }
  },
  goCall(e) {
  const phoneNumber = this.data.store_info.phone
    wx.makePhoneCall({
        phoneNumber
    });
  },
  goOrderDetial(e) {
    const id = this.data.id
    wx.navigateTo({
        url: `../orderDetail/orderDetail?id=${id}`
    });
  },
  toNavigation(){
    const store_info = this.data.store_info
    wx.openLocation({
      latitude: store_info.address_coordinate_latitude || 39.90469,  // 目标纬度，浮点数，范围为-90~90
      longitude: store_info.address_coordinate_longitude ||  116.40717, // 目标经度，浮点数，范围为-180~180
      name: store_info.name || '天安门广场',    // 位置名
      address: store_info.address || '北京市东城区', // 详细地址
      scale: 16,           // 地图缩放级别，整形值，范围从1~28
      success: function() {
        console.log('打开地图成功');
      },
      fail: function(err) {
        console.error('打开地图失败:', err);
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
   this.setData({
      id: options.id,
    }, ()=>{
      this.getInfo()
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      reservationInfo: app.globalData.reservationInfo,
    });
    console.log(this.data.reservationInfo)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return {
      title: '频繁染白发，就找染博士',
      imageUrl:
        'https://ranboss.oss-cn-beijing.aliyuncs.com/ranstore/share.png',
    };
  }
})